//
//  DataViewController.m
//  AntsExpress
//
//  Created by slccper on 16/1/14.
//  Copyright © 2016年 slccper. All rights reserved.
//

#import "DataViewController.h"
#import "AntsPickView.h"
@interface DataViewController ()
{
    AntsPickView *pickview;
}
@property (weak, nonatomic) IBOutlet UITextField *LoginName;
@property (weak, nonatomic) IBOutlet UITextField *RealName;
@property (weak, nonatomic) IBOutlet UIButton *Sex;
@property (weak, nonatomic) IBOutlet UIButton *Birthday;
@property (weak, nonatomic) IBOutlet UITextField *Photo;
@property (weak, nonatomic) IBOutlet UITextField *weChat;
@property (weak, nonatomic) IBOutlet UITextField *qq;
@property (weak, nonatomic) IBOutlet UITextField *Email;
@property (weak, nonatomic) IBOutlet UITextField *Adress;

@end

@implementation DataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"會員資料";
    self.LoginName.text = [clsOtherFun getName];
    self.RealName.text = [clsOtherFun getRealName];
    self.Photo.text = [clsOtherFun getMemberPhone];
    self.weChat.text = [clsOtherFun getwechart];
    self.qq.text = [clsOtherFun getQQ];
    self.Email.text = [clsOtherFun getEmail];
    self.Adress.text = [clsOtherFun getAddress];
    self.Sex.titleLabel.text = [clsOtherFun getMemberSex];
    self.Birthday.titleLabel.text = [clsOtherFun getBirthday];
    ants = [[clsAntsService alloc]init];
    ants.delegate =self;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)cancel
{
    [self.view endEditing:YES];
}
- (IBAction)BirthdayAction:(id)sender {
    [self cancel];
    NSString *str = [clsOtherFun getBirthday];
    
    pickview = [[AntsPickView alloc]initDatePickWithDate:[NSDate date] :[NSDate date] datePickerMode:UIDatePickerModeDate];
    [pickview show:^(NSString *pSelectData, NSInteger cIndex) {
        self.Birthday.titleLabel.text =pSelectData;
    }];pickview =nil;
}
- (IBAction)SexAction:(id)sender {
    [self cancel];
    NSString *str = [clsOtherFun getMemberSex];
    
    pickview = [[AntsPickView alloc]initPickviewWithArray:@[@"男",@"女"]];
    [pickview show:^(NSString *pSelectData, NSInteger cIndex) {
        self.Sex.titleLabel.text =pSelectData;
    }];
}

- (IBAction)SubmitAction:(id)sender {
    NSString *RealName = self.RealName.text;
//    if ([RealName isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入真實姓名"];
//        [self.RealName becomeFirstResponder];
//        return;
//    }
    NSString *phone = self.Photo.text;
//    if ([phone isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入手機號碼"];
//        [self.Photo becomeFirstResponder];
//        return;
//    }
    NSString *weChat = self.weChat.text;
//    if ([weChat isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入微信"];
//        [self.weChat becomeFirstResponder];
//        return;
//    }
    NSString *qq = self.qq.text;
//    if ([qq isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入QQ"];
//        [self.qq becomeFirstResponder];
//        return;
//    }
    NSString *Email = self.Email.text;
//    if ([Email isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入Email"];
//        [self.Email becomeFirstResponder];
//        return;
//    }
    NSString *Adress = self.Adress.text;
//    if ([Adress isEqualToString:@""]) {
//        [clsOtherFun ShowMsg:@"請輸入地址"];
//        [self.Adress becomeFirstResponder];
//        return;
//    }
    NSString *sex = self.Sex.titleLabel.text;
    NSString *Birthday = self.Birthday.titleLabel.text;
    if ([clsOtherFun CheckNetworkStatus:YES]) {
        [clsOtherFun showLoadingView:@"正在更新資料..."];
         [ants UpdateUser:RealName :qq :weChat :Adress :Email :phone :sex];
    }else{
        [clsOtherFun ShowNoNetworkMsg];
    }
   
}
-(void)getAntsDataSuccess:(NSInteger)type :(NSMutableDictionary *)pDictionary
{
    [clsOtherFun hideLoadingView];
    NSDictionary *dic = [pDictionary objectForKey:@"data"];
    NSString *status = [dic objectForKey:@"status"];
    if ([status integerValue]==200) {
        [clsOtherFun setReName:self.RealName.text];
        [clsOtherFun setMemberPhone:self.Photo.text];
        [clsOtherFun setEmail:self.Email.text];
        [clsOtherFun setwechart:self.weChat.text];
        [clsOtherFun setqq:self.qq.text];
        [clsOtherFun setAddress:self.Adress.text];
        [clsOtherFun setMemberSex:self.Sex.titleLabel.text];
    }
    
    [clsOtherFun ShowMsg:[dic objectForKey:@"message"]];
}
@end
